package com.frank.oj.controller.oj;

import com.frank.model.entity.problem.Language;
import com.frank.model.entity.problem.Tag;
import com.frank.oj.annotation.AnonApi;
import com.frank.oj.common.result.CommonResult;
import com.frank.oj.model.vo.CaptchaVO;
import com.frank.oj.model.vo.CommentListVO;
import com.frank.oj.model.vo.ProblemTagVO;
import com.frank.oj.service.oj.CommonService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * @author frank
 * @Date 2024/3/22
 */
@RestController
@RequestMapping("/api")
public class CommonController {

    @Resource
    private CommonService commonService;

    /**
     * 获取oj的题目标签和分类
     *
     * @param oj oj类型，默认me
     * @return 返回oj的题目标签和分类
     */
    @GetMapping("get-problem-tags-and-classification")
    public CommonResult<List<ProblemTagVO>> getProblemTagsAndClassification(@RequestParam(value = "oj", defaultValue = "ME") String oj) {
        return commonService.getProblemTagsAndClassification(oj);
    }

    /**
     * 获取所有标签
     *
     * @param oj oj类型，默认me
     * @return 返回oj的题目标签和分类
     */
    @GetMapping("/get-all-problem-tags")
    @AnonApi
    public CommonResult<List<Tag>> getAllProblemTags(@RequestParam(value = "oj", defaultValue = "ME") String oj) {
        return CommonResult.successResponse(commonService.getAllProblemTags(oj));
    }
    @GetMapping("/get-problem-tags")
    @AnonApi
    public CommonResult<Collection<Tag>> getProblemTags(Long pid) {
        return CommonResult.successResponse(commonService.getProblemTags(pid));
    }

    @GetMapping("/languages")
    @AnonApi
    public CommonResult<List<Language>> getLanguages(@RequestParam(value = "pid", required = false) Long pid,
                                                     @RequestParam(value = "all", required = false) Boolean all){
        return CommonResult.successResponse(commonService.getLanguages(pid, all));
    }

    @GetMapping("/captcha")
    @AnonApi
    public CommonResult<CaptchaVO> getCaptcha() {
        return commonService.getCaptcha();
    }

}
